import {proxy} from "@@/exports";

export interface AwardType {
    id: string;
    awardName: string;
    awardHeadImg: string;
    receiveRule: string;
    receiveLimit: number;
}

export interface PageItemType {
    id: string;
    type: "image" | "button" | "award";
    text?: string;
    url?: string;
    award?: AwardType[];
}

export interface ActivityModelType {
    currentItem?: PageItemType;
    pageData: PageItemType[];
}

const state = proxy<ActivityModelType>({
    pageData: [{
        id: "1",
        type: "image",
        url: "https://img.tuguaishou.com/ips_templ_preview/d4/dd/37/lg_154884_1520792683_5aa5746be45ea.jpg!w280?auth_key=1679559371-0-0-a694a1196724b758709775145fbb0bd8"
    },
        {
            id: "2",
            type: "award",
            url: "https://img.tuguaishou.com/ips_templ_preview/d4/dd/37/lg_154884_1520792683_5aa5746be45ea.jpg!w280?auth_key=1679559371-0-0-a694a1196724b758709775145fbb0bd8",
            award: [
                {
                    id: "1",
                    awardName: "小米手机",
                    awardHeadImg: "https://img.tuguaishou.com/ips_templ_preview/d4/dd/37/lg_154884_1520792683_5aa5746be45ea.jpg!w280?auth_key=1679559371-0-0-a694a1196724b758709775145fbb0bd8",
                    receiveRule: "all",
                    receiveLimit: 500,
                },
                {
                    id: "2",
                    awardName: "2999全家福套系",
                    awardHeadImg: "https://img.tuguaishou.com/ips_templ_preview/d4/dd/37/lg_154884_1520792683_5aa5746be45ea.jpg!w280?auth_key=1679559371-0-0-a694a1196724b758709775145fbb0bd8",
                    receiveRule: "all",
                    receiveLimit: 350,
                },
            ]
        }]
})

const actions = {
    addItem(item: PageItemType) {
        state.pageData.push(item)
    },
    setCurrentItem(item: PageItemType) {
        state.currentItem = item
    },
    flushPageData() {
        let item = state.pageData.find(item => item.id === state.currentItem?.id);
        let indexOf = state.pageData.indexOf(item);
        state.pageData.splice(indexOf, 1, state.currentItem)
        console.log(indexOf)
    },
}
export const CreatePageModel = {state, actions}